package cn.pconline.autoclub.entity;

import cn.pconline.autoclub.util.EncodeUtils;

import com.alibaba.fastjson.JSONObject;

import java.util.Date;
import java.util.HashMap;

import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Transient;

/**
 * 车友会
 *
 * @author chensy
 */
@Entity(tableName = "ac_club", logChange = true)
public class Club {

    @Id
    @Column(name = "club_id")
    private long clubId;// 车友会ID
    @Column(name = "name")
    private String name;//名称
    @Column(name = "introduce")
    private String introduce;//简介
    @Column(name = "region_id")
    private long regionId;//所属地址分区Id
    @Column(name = "region_name")
    private String regionName;//所属地址分区
    @Column(name = "province_id")
    private long provinceId;//所属省份Id
    @Column(name = "province_name")
    private String provinceName;//所属省份
    @Column(name = "city_id")
    private long cityId;//所属城市Id
    @Column(name = "city_name")
    private String cityName;//所属城市
    @Column(name = "brand_name")
    private String brandName;//品牌名称
    @Column(name = "series_name")
    private String seriesName;//车系名称
    @Column(name = "logo")
    private String logo;//车标
    @Column(name = "create_by")
    private long createBy;//创建者
    @Column(name = "create_at")
    private Date createAt;//创建时间==申请时间
    @Column(name = "update_at")
    private Date updateAt;//更新时间
    @Column(name = "admin_id")
    private long adminId;//会长Id 判断是否是会长时，该字段没有用！！！
    @Column(name = "level_id")
    private long levelId;//等级 默认为0 初建期
    @Column(name = "qq_group")
    private String qqGroup; //qq群
    @Column(name = "reject_msg")
    private String rejectMsg; //拒绝消息
    public static final int STATUS_UNAUDITED = 0;//未审
    public static final int STATUS_PASS = 1;//通过
    public static final int STATUS_REJECTED = 2;//拒绝
    public static final int STATUS_SEALED = 3; //封
    public static final int STATUS_LOCK = 4; //锁 
    public static final HashMap<Integer, String> statusDesc = new HashMap<Integer, String>();
    public static String LOGO_DEF_PC = "http://www1.pcauto.com.cn/2014/club/v4_1/common/defaultphoto2_150x150.jpg";
    public static String LOGO_DEF = "http://www1.pcauto.com.cn/bbs/cargroup/2014/images/defaultphoto2.png";
    static {
        statusDesc.put(STATUS_UNAUDITED, "未审核");
        statusDesc.put(STATUS_PASS, "已通过");
        statusDesc.put(STATUS_REJECTED, "拒绝");
        statusDesc.put(STATUS_LOCK, "已锁定");
        statusDesc.put(STATUS_SEALED, "已封");
    }
    @Column(name = "status")
    private int status;//状态,0未审,1已审,2拒绝,3封,4锁定
    @Column(name = "brand_id")
    private long brandId;//品牌ID
    @Column(name = "series_id")
    private long seriesId;//车系ID
    @Column(name = "update_by")
    private long updateBy;//更新者
    @Column(name = "vip_num")
    private int vipNum;//认证人数
    @Column(name = "member_num")
    private int memberNum;//会员人数
    @Column(name = "reply_num")
    private long replyNum;//回复总数
    @Column(name = "topic_num")
    private long topicNum;//主题贴总数
    @Column(name = "audit_at")
    private Date auditAt;//审核时间
    @Column(name = "audit_by")
    private long auditBy;//审核人
    @Transient(cache = false)
    private User creator;
    @Transient(cache = false)
    private ClubAddress address;
    @Column(name = "total_petrol")
    private long totalPetrol;//总油值，不常更新字段，需要实时更新的见 petrol下的totalPetrol
    @Transient(cache = false)
    private ClubPetrol petrol;
    @Transient(cache = false)
    private ClubLevel level;
    @Column(name = "rank")
    private int rank;//全国排名，不常更新字段
    @Column(name = "day_rank")
    private int dayRank;//全国排名，不常更新字段
    @Column(name = "club_url")
    private String clubUrl;//车友会个性域名
    /**
     * 目前已经不存在分区排名了，由于历史原因，分区排名实际是品牌排名
     */
    @Column(name = "region_rank")
    private int regionRank;//分区排名
    @Column(name = "day_region_rank")
    private int dayRegionRank;//昨天分区排名
    @Column(name = "brand_rank")
    private int brandRank;//品牌排名
    @Column(name = "day_brand_rank")
    private int dayBrandRank;//昨天品牌排名
    @Column(name = "province_rank")
    private int provinceRank;//品牌排名
    @Column(name = "day_province_rank")
    private int dayProvinceRank;//昨天品牌排名
    @Column(name = "type")
    private int type;//类型：1-地区，2-车系，3-主题
    public static final int TYPE_AREA = 1;//地区
    public static final int TYPE_SERIAL = 2;//车系
    public static final int TYPE_THEME = 3;//主题
    @Column(name = "theme_id")
    private long themeId;//主题id
    @Transient(cache = false)
    private Theme theme;
    @Column(name = "app_banner")
    private String appBanner;//app、wap车友会封面
    @Column(name = "banner_id")
    private long bannerId;//车友会通栏ID
    @Transient(cache = false)
    private ClubDispose clubDispose; //处理情况

    public int getDayRank() {
        return dayRank;
    }

    public void setDayRank(int dayRank) {
        this.dayRank = dayRank;
    }

    public int getDayRegionRank() {
        return dayRegionRank;
    }

    public void setDayRegionRank(int dayRegionRank) {
        this.dayRegionRank = dayRegionRank;
    }

    public int getBrandRank() {
        return brandRank;
    }

    public void setBrandRank(int brandRank) {
        this.brandRank = brandRank;
    }

    public int getDayBrandRank() {
        return dayBrandRank;
    }

    public void setDayBrandRank(int dayBrandRank) {
        this.dayBrandRank = dayBrandRank;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public long getThemeId() {
        return themeId;
    }

    public void setThemeId(long themeId) {
        this.themeId = themeId;
    }

    public String getAppBanner() {
        return appBanner;
    }

    public void setAppBanner(String appBanner) {
        this.appBanner = appBanner;
    }

    public long getBannerId() {
        return bannerId;
    }

    public void setBannerId(long bannerId) {
        this.bannerId = bannerId;
    }

    public int getRegionRank() {
        return regionRank;
    }

    public void setRegionRank(int regionRank) {
        this.regionRank = regionRank;
    }

    public String getClubUrl() {
        return StringUtils.isBlank(clubUrl) ? clubId + "" : clubUrl;
    }

    public void setClubUrl(String clubUrl) {
        this.clubUrl = clubUrl;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public long getTotalPetrol() {
        return totalPetrol;
    }

    public void setTotalPetrol(long totalPetrol) {
        this.totalPetrol = totalPetrol;
    }

    public ClubLevel getLevel() {
        return level;
    }

    public void setLevel(ClubLevel level) {
        this.level = level;
    }

    public ClubPetrol getPetrol() {
        return petrol;
    }

    public void setPetrol(ClubPetrol petrol) {
        this.petrol = petrol;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public ClubAddress getAddress() {
        return address;
    }

    public void setAddress(ClubAddress address) {
        this.address = address;
    }

    public long getClubId() {
        return clubId;
    }

    public void setClubId(long clubId) {
        this.clubId = clubId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    public long getRegionId() {
        return regionId;
    }

    public void setRegionId(long regionId) {
        this.regionId = regionId;
    }

    public String getRegionName() {
        return regionName;
    }

    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    public long getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(long provinceId) {
        this.provinceId = provinceId;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public long getCityId() {
        return cityId;
    }

    public void setCityId(long cityId) {
        this.cityId = cityId;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getBrandName() {
        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public String getSeriesName() {
        return seriesName;
    }

    public void setSeriesName(String seriesName) {
        this.seriesName = seriesName;
    }

    public String getLogo() {
        if (StringUtils.isNotBlank(logo)) {
            return logo;
        }
        return LOGO_DEF;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public long getAdminId() {
        return adminId;
    }

    public void setAdminId(long adminId) {
        this.adminId = adminId;
    }

    public long getLevelId() {
        return levelId;
    }

    public void setLevelId(long levelId) {
        this.levelId = levelId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public long getBrandId() {
        return brandId;
    }

    public void setBrandId(long brandId) {
        this.brandId = brandId;
    }

    public long getSeriesId() {
        return seriesId;
    }

    public void setSeriesId(long seriesId) {
        this.seriesId = seriesId;
    }

    public long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(long updateBy) {
        this.updateBy = updateBy;
    }

    public int getVipNum() {
        return vipNum;
    }

    public void setVipNum(int vipNum) {
        this.vipNum = vipNum;
    }

    public int getMemberNum() {
        return memberNum;
    }

    public void setMemberNum(int memberNum) {
        this.memberNum = memberNum;
    }

    public long getReplyNum() {
        return replyNum;
    }

    public void setReplyNum(long replyNum) {
        this.replyNum = replyNum;
    }

    public long getTopicNum() {
        return topicNum;
    }

    public void setTopicNum(long topicNum) {
        this.topicNum = topicNum;
    }

    public Date getAuditAt() {
        return auditAt;
    }

    public void setAuditAt(Date auditAt) {
        this.auditAt = auditAt;
    }

    public long getAuditBy() {
        return auditBy;
    }

    public void setAuditBy(long auditBy) {
        this.auditBy = auditBy;
    }

    public String getQqGroup() {
        return qqGroup;
    }

    public void setQqGroup(String qqGroup) {
        this.qqGroup = qqGroup;
    }

    public ClubDispose getClubDispose() {
        return clubDispose;
    }

    public void setClubDispose(ClubDispose clubDispose) {
        this.clubDispose = clubDispose;
    }

    public String getRejectMsg() {
        return rejectMsg;
    }

    public void setRejectMsg(String rejectMsg) {
        this.rejectMsg = rejectMsg;
    }

    public int getProvinceRank() {
        return provinceRank;
    }

    public void setProvinceRank(int provinceRank) {
        this.provinceRank = provinceRank;
    }

    public int getDayProvinceRank() {
        return dayProvinceRank;
    }

    public void setDayProvinceRank(int dayProvinceRank) {
        this.dayProvinceRank = dayProvinceRank;
    }
    
    public Theme getTheme() {
    	return theme;
    }

	public void setTheme( Theme theme ) {
    	this.theme = theme;
    }
    public String converLogo(String size){
         if(StringUtils.isBlank(logo)){
            return LOGO_DEF;
        }
         if(logo.indexOf("_135x100")!=-1){
              return logo.replace("_135x100", "_150x150");
        }
        return logo.replace(".jpg", "_"+size+".jpg");
    }
    public String getLogo150x150(){
        if(!isHasLogo()){
            return LOGO_DEF_PC;
        }
        return converLogo("150x150");
    }
    
    public boolean isHasLogo() {
        if(Club.LOGO_DEF_PC.equals(getLogo())) {
            return false;
        }
        if(Club.LOGO_DEF.equals(getLogo())) {
            return false;
        }
        return true;
    }
    
	public JSONObject toJson(){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("clubId", getClubId());
        jsonObject.put("clubUrl", getClubUrl());
        jsonObject.put("clubStatus", getStatus());
        jsonObject.put("name", getName());
        jsonObject.put("logo", getLogo());
        jsonObject.put("memberNum", getMemberNum());        
        jsonObject.put("level", getLevelId());
        jsonObject.put("brandId", getBrandId());
        jsonObject.put("brandName", getBrandName());        
        jsonObject.put("regionRank", getRegionRank());
        jsonObject.put("brandRank", getBrandRank());
        jsonObject.put("provinceRank", getProvinceRank());
        jsonObject.put("rank", getRank());
        jsonObject.put("qqGroup", getQqGroup());
        jsonObject.put("vipNum", getVipNum());
        jsonObject.put("totalPetrol", getTotalPetrol());        
        jsonObject.put("seriesName", getSeriesName());
        jsonObject.put("seriesId", getSeriesId());
        jsonObject.put("provinceId", getProvinceId());
        jsonObject.put("provinceName", getProvinceName());
        jsonObject.put("cityId", getCityId());
        jsonObject.put("cityName", getCityName());
        jsonObject.put("introduce", getIntroduce());        
        jsonObject.put("addressCityId", getCityId());
        jsonObject.put("appBanner", getAppBanner());
                 
        return jsonObject;        
    }    
    
    public JSONObject toJsonEncodeHTML(){
        JSONObject jsonObject = toJson();
        jsonObject.put("name", EncodeUtils.encodeForHTMLFilterNull(getName()));
        jsonObject.put("seriesName", EncodeUtils.encodeForHTMLFilterNull(getSeriesName()));
        jsonObject.put("provinceName", EncodeUtils.encodeForHTMLFilterNull(getProvinceName()));
        jsonObject.put("cityName", EncodeUtils.encodeForHTMLFilterNull(getCityName()));
        jsonObject.put("introduce", EncodeUtils.encodeForHTMLFilterNull(getIntroduce())); 
        jsonObject.put("appBanner", EncodeUtils.encodeForHTMLFilterNull(getAppBanner()));
        return jsonObject;
    }
}
